package gapidt.analysis;

import gapidt.nlp.SemanticUtils;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;

public class APIDesignAnalysisUtils {
	
	/**
	 * Determines if the given method is a service method. This means it should be analyzed
	 */
	public static boolean isServiceMethod(IMethod method){
		
		try {
			
			//Discard constructors and not public methods
			if(method.isConstructor() || !ASTUtils.isPublic(method)){
				return false;
			}
			
			/*String methodName = method.getElementName().toString();
					
			//Discard getters and setters
			if(methodName.startsWith("get") || 
			   methodName.startsWith("set") ||
			   methodName.startsWith("is")){
				
				Set<String> normalizedAttributeNames = new HashSet<String>();
				
				if(method.getParent() != null && method.getParent() instanceof IType){
					IType type = (IType) method.getParent();
					
					for(IField typeAttribute : type.getFields()){
						String normalizedName = SemanticUtils.camelCase2Underscores(typeAttribute.getElementName().toString()).toLowerCase();
						normalizedAttributeNames.add(normalizedName);
					}
				}
				
				String methodNormalizedLastPart = SemanticUtils.camelCase2Underscores(methodName.replaceAll("^(is|get|set)", "")).toLowerCase();
				if(normalizedAttributeNames.contains(methodNormalizedLastPart)){
					return false;
				}else{
					return true;
				}
			}*/
			
		} catch (JavaModelException e) {
			return false;
		}
		
		return true;
	}
	
}
